<?php

namespace apps\marriage\app\mp\controller;

use apps\marriage\core\service\UserAccountBookService;
use think\Request;

class MyWalletController extends BaseMarriageMpController
{
    /**
     * @var UserAccountBookService
     */
    private $userAccountBookService;

    protected function init()
    {
        parent::init();
        $this->userAccountBookService = service('UserAccountBook', SERVICE_NAMESPACE);
    }

    public function record(Request  $request)
    {
        $pageSize = $request->param('page_size', 10, 'intval');
        $params = [
            'user_id' => $this->user['id']
        ];
        $res = $this->userAccountBookService->pageListByParams($params, $pageSize);
        foreach ($res['data'] as &$item) {
            $item = $this->userAccountBookService->format($item);
        }
        return $this->success($res);
    }

    public function account()
    {
        return $this->success([
            'gold_coin' => $this->user['gold_coin'],
            'balance' => $this->user['balance'],
            'withdraw_balance' => $this->user['withdraw_balance'],
            'withdrawing_balance' => $this->user['withdrawing_balance'],
        ]);
    }
}